#include "inc/god.h"

#include <pthread.h> // about thread mutex


#define SERVER_IP "127.0.0.1"
#define SERVER_PORT 12100

#define MSG_LENGTH 1024

int main2(int argc, char *argv[])
{
#if 0
    pthread_t t[128];

    char buf[MSG_LENGTH];

    int i = 128;
    int count = 0;

    while(1){
        i = 128;
        while(i--){
            pthread_create(&t[i], NULL, main2, handle);
            count++;
            //sendNetBuff(handle);
        }

        printf("%d\n", count);
    }


    for(int i = 0; i < 128; i++){
       pthread_join(t[i],NULL);
    }
#endif
    return 0;
}

int main(int argc, char *argv[]){

    int  sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);

    struct sockaddr_in svraddr;

    svraddr.sin_family = AF_INET;
    //inet_pton(AF_INET, "127.0.0.1", &seraddr.sin_addr);
    svraddr.sin_addr.s_addr = inet_addr("127.0.0.1");
    svraddr.sin_port = htons(12100);

    int ret = connect(sockfd, (struct sockaddr*)&svraddr, sizeof(svraddr));
    // udp connect , 仅判断sockfd对应主机是否可达, 再保存 IP PORT 信息

    char buff[] = "Hello, UDP Client!";

    int nsend = send(sockfd, buff, strlen(buff), 0);
    printf("nsend = %d\n", nsend);

    recv(sockfd, buff, sizeof(buff), 0);

    printf("%s\n", buff);
    return 0;
}

